<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
  

<table class="table">
  <tr>
    <th>id</th>
    <th>用户名</th>
    <th>注册时间</th>
    <th>角色</th>
    <th>状态</th>
    <th>操作</th>
  </tr>
  
  <!-- userPage -->
  <c:forEach items="${userPage.list}" var="user">
	  <tr>
	    <td>${user.id}</td>
	    <td>${user.username}</td>
	    <td><fmt:formatDate value="${user.createTime}" pattern="yyyy-MM-dd"/></td>
	    
	    <td>${user.role==1?'管理员':'注册用户'}</td>
	    
	    <td>${user.locked==1?'被封':'正常'}</td>
	    <td>
	    	<c:if test="${user.locked==1}">
	    		<button type="button" class="btn btn-success" onclick="userlock(${user.id},0)">解禁</button>
	    	</c:if>
	    	<c:if test="${user.locked==0}">
				<button type="button" class="btn btn-danger" onclick="userlock(${user.id},1)" >封禁</button>
			</c:if>
		</td>
	  </tr>
  </c:forEach>
  
  
</table>
<nav aria-label="...">
  <ul class="pagination">
   	 <li><a href="javascript:goPage(${userPage.prePage})">&laquo;</a></li>
    <c:forEach begin="${userPage.pageNum-2 > 1 ? userPage.pageNum-2:1}" end="${userPage.pageNum+2 > userPage.pages ? userPage.pages:userPage.pageNum+2}" varStatus="index">    		
    	<c:if test="${userPage.pageNum!=index.index}">
    		<li><a href="javascript:goPage(${index.index})">${index.index}</a></li>
    	</c:if>
    	<c:if test="${userPage.pageNum==index.index}">
    		<li><a href="javascript:void"><strong> ${index.index} </strong> </a></li>
    	</c:if>
    	
    </c:forEach>
    <li><a href="javascript:goPage(${info.nextPage})">&raquo;</a></li>
  </ul>
</nav>

<script type="text/javascript">

	function goPage(page){
		$("#workContent").load("/admin/userlist?page="+page)
	}
	
	function userlock(userId,lockStatus){
		
		if(confirm("确实要处理该用户么？")){
			$.post("/admin/userlock",{userid:userId,status:lockStatus},function(msg){
				if(msg=="success"){
					//处理成功
					alert('d')
					$("#workContent").load("/admin/userlist?page="+'${userPage.pageNum}')
				}
			})
		}
	}
	
</script>
    